package sunstar.com.xq.presenter

import android.bluetooth.BluetoothProfile
import cn.bmob.v3.exception.BmobException
import cn.bmob.v3.listener.SaveListener
import sunstar.com.xq.databean.UserData
import sunstar.com.xq.util.UtilBox
import sunstar.com.xq.view.RegistView

/**
 * Created by Sun.Star on 2017/6/7.
 */
class RegistPresenter (var regisView:RegistView){
    public fun regist(number:String,code:String,passWord:String){

        var user = UserData()
        user.username = number
        user.setPassword(passWord)
        user.signUp(object : SaveListener<UserData>(){
            override fun done(p0: UserData?, p1: BmobException?) {
                if(p1 == null){
                    regisView.registComplet("")
                }else{
                    regisView.registError(p1.message.toString())
                }
            }

        })
    }
    public fun getCode(number:String){
        if(number.equals("")){
            regisView.numberError("请输入手机号")
            return
        }
        if(!UtilBox.isMobile(number)){
            regisView.codeError()
        }else{
            regisView.getCode()
        }

    }
    fun checkNumber(number:String,code:String,passWord:String) : Boolean{
        if(number.equals("")){
            regisView.numberError("请输入手机号")
            return false
        }
        if(code.equals("")){
            regisView.numberError("请输入验证码")
            return false
        }
        if(passWord.equals("")){
            regisView.numberError("请输入密码")
            return false
        }
        if(!UtilBox.isMobile(number)){
            regisView.numberError("请输入正确")
            return false
        }
        if(code.length<6){
            regisView.numberError("请输入正确验证码")
            return false
        }
        if(passWord.length<6){
            regisView.numberError("请输入大于6位的密码")
            return false
        }
        return true
    }
}